package com.apps.globals.activity.service.impl;

import com.apps.globals.activity.enums.ActivityType;
import com.apps.globals.activity.model.po.KupaActivity;
import com.apps.globals.activity.dao.KupaActivityMapper;
import com.apps.globals.activity.service.IKupaActivityService;
import com.apps.sworld.dao.impl.sDaoImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 大鹏
 * @since 2020-10-02
 */
@Service
public class KupaActivityServiceImpl extends sDaoImpl<KupaActivityMapper, KupaActivity> implements IKupaActivityService
{

    @Override
    public KupaActivity getOne(ActivityType activityType, BigDecimal trade_price)
    {
        QueryWrapper<KupaActivity> wrapper=new QueryWrapper<>();
        wrapper.eq("type",activityType.name());
        //这里只能求小于,所以实际设置活动触发价格得写小一位数
        wrapper.lt("condition_price",trade_price);
        wrapper.lt("unix_timestamp(gmt_start)", LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));
        wrapper.gt("unix_timestamp(gmt_end)",LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));
        return getOne(wrapper);
    }

    @Override
    public KupaActivity getOne(Integer goods_cat_id, ActivityType activityType, BigDecimal trade_price)
    {
        QueryWrapper<KupaActivity> wrapper=new QueryWrapper<>();
        wrapper.eq("type",activityType.name());
        //这里只能求小于,所以实际设置活动触发价格得写小一位数
        wrapper.lt("condition_price",trade_price);
        wrapper.lt("unix_timestamp(gmt_start)", LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));
        wrapper.gt("unix_timestamp(gmt_end)",LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));
        return getOne(wrapper);
    }
}
